#include<bits/stdc++.h>
using namespace std;
int T,n,a[2005],mx,c;
void dfs(int x,int r,int b,int sum){
    if(x==n+1){
        mx=max(mx,sum);
        return ;
    }
    c=c*10+1;
    if(a[r]==a[x]) dfs(x+1,x,b,sum+a[x]);
    else dfs(x+1,x,b,sum);
    c++;
    if(a[b]==a[x]) dfs(x+1,r,x,sum+a[x]);
    else dfs(x+1,r,x,sum);
    c/=10;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n;
        mx=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        dfs(1,0,0,0);
        cout<<mx<<"\n";
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
